#include <iostream>
#include <queue>
#include <vector>

using namespace std;
const int N = 510;
vector<int>edges[N];
queue<int>q;
int in[N];
int n;
bool st[N];
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x, m, y; cin >> x >> m;
		st[x] = true;
		for (int j = 1; j <= m; j++)
		{
			cin >> y;
			edges[x].push_back(y);
			in[y]++;
		}
	}
	queue<int> q;
	for (int i = 1; i <= 500; i++)
	{
		if (st[i] && in[i] == 0) q.push(i);
	}
	while (q.size())
	{
		auto t = q.front(); q.pop();
		for (auto& k : edges[t])
		{
			in[k]--;
			if (st[k] && in[k] == 0) q.push(k);
		}
	}
	int ret = 0;
	for (int i = 1; i <= 500; i++)
	{
		if (st[i] && in[i]) ret++;
	}
	if (ret == 0) cout << "YES" << endl;
	else cout << ret << endl;
	return 0;
}